package com.zxy.supplier_system.server.utils.wechat.official

import com.zxy.supplier_system.server.utils.wechat.validate200ErrorCodeAndMessageResponse
import org.springframework.web.client.getForEntity

data class WechatUserInfo(
    val subscribe: Int,
    val unionid: String?,
    val openid: String,
)

fun WechatOfficialAccountHelper.getUserInfo(openId: String): WechatUserInfo {
    val accessToken = getOrFetchAccessToken()
    val entity =
        restTemplate.getForEntity<Map<String, Any>>("https://api.weixin.qq.com/cgi-bin/user/info?access_token=$accessToken&openid=${openId}&lang=zh_CN")
    return validate200ErrorCodeAndMessageResponse(entity, WechatUserInfo::class.java)
}